from django.shortcuts import render
from .settings import *
import requests
# Create your views here.
def asser_buyer(request):
    """
                @author:薛威宁
                @date:2018/10/20/
                提交方式 ：POST
                提交数据格式 ：{提交数据库格式:{"asset_name"："xxx","pur_name"："x",user"："xx","save_room"："仓库"}
    仓库格式:{'asset_name':'xxx','room':'xxx','asset_num':'数字'}
            """
    if request.method == 'POST':
        info = dict(request.POST)
        print(info)
        url_ip = url + 'asset/asser_buyer/'
        r = requests.post(url_ip, data=info)
        print(r.text)
        rt = r.json['message']
        if rt == '资产已入库':
            context = {'message':rt}
            return render(request, 'apiasset/asset_by.html',context)
        else:
            context = {'message': '购买成功'}
            return render(request, 'apiasset/asset_by.html',context)
    elif request.method == 'GET':
        return render(request, 'apiasset/asset_by.html')


